home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / ease-3.5 / src / symtab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-15  |  6.6 KB  |  262 lines

  1. #ifdef FLUKE
  2. # ifndef LINT
  3.     static char RCSid[] = "@(#)FLUKE  $Header: /tmp_mnt/home/kreskin/u0/barnett/Src/Ease/ease/src/RCS/symtab.c,v 3.1 1991/09/09 16:33:23 barnett Exp $";
  4. # endif LINT
  5. #endif FLUKE
  6.  
  7. /*
  8.  *      symtab.c   -- Contains Ease Translator symbol table routines.
  9.  *
  10.  *      author     -- James S. Schoner, Purdue University Computing Center,
  11.  *                        West Lafayette, Indiana  47907
  12.  *
  13.  *      date       -- July 9, 1985
  14.  *
  15.  *    Copyright (c) 1985 by Purdue Research Foundation
  16.  *
  17.  *    All rights reserved.
  18.  *
  19.  * $Log: symtab.c,v $
  20.  * Revision 3.1  1991/09/09  16:33:23  barnett
  21.  * Minor bug fix release
  22.  *
  23.  * Revision 3.0  1991/02/22  18:50:27  barnett
  24.  * Added support for HP/UX and IDA sendmail.
  25.  *
  26.  * Revision 2.1  1990/01/30  15:55:54  jeff
  27.  * SunOS/Ultrix/Ida additions Jan 25 1988 Bruce Barnett
  28.  *
  29.  * Revision 2.0  88/06/15  14:43:04  root
  30.  * Baseline release for net posting. ADR.
  31.  */
  32.  
  33. #include "fixstrings.h"
  34. #include <stdio.h>
  35. #include <ctype.h>
  36. #include "symtab.h"
  37.  
  38. #define ERRORMAILER "error"        /* predefined error mailer name */
  39. #define ERRORMAILERUC "ERROR"        /* predefined ERROR mailer name */
  40.  
  41. extern void FatalError (),
  42.         PrintWarning ();
  43.  
  44. struct he *LookupSymbol ();
  45.  
  46. struct Defmac {                /* predefined macro struct def  */
  47.     char *macname;
  48.     char  macrep;
  49. };
  50.  
  51. static struct he *SymTab[SST];        /* hash table base array        */
  52. static struct Defmac MacDefs[] = {    /* predefined macros            */
  53.             {"m_smtp",    'e'},
  54.             {"m_oname",    'j'},
  55.             {"m_uucpname",    'k'}, /* IDA */
  56.             {"m_ufrom",    'l'},
  57.             {"m_daemon",    'n'},
  58.             {"m_domain",    'm'},    /* SunOS */
  59.             {"m_addrops",    'o'},
  60.             {"m_defaddr",    'q'},
  61.             {"m_sitename",    'w'},
  62.             {"m_odate",    'a'},
  63.             {"m_adate",    'b'},
  64.             {"m_hops",    'c'},
  65.             {"m_udate",    'd'},
  66.             {"m_saddr",    'f'},
  67.             {"m_sreladdr",    'g'},
  68.             {"m_rhost",    'h'},
  69.             {"m_qid",    'i'},
  70.             {"m_pid",    'p'},
  71.             {"m_protocol",    'r'},
  72.             {"m_shostname", 's'},
  73.             {"m_ctime",    't'},
  74.             {"m_ruser",    'u'},
  75.             {"m_version",    'v'},
  76.             {"m_sname",    'x'},
  77.             {"m_stty",    'y'},
  78.             {"m_rhdir",    'z'},
  79.             {"sentinel",    '\0'}
  80. };
  81.  
  82. /* FLUKE jps 28-apr-86 - Install some wired-in class names */
  83. static struct Defmac ClassDefs[] = {    /* predefined classes */
  84.             {"c_myname",    'w'},
  85.             {"c_mydomain",    'm'},
  86.             {"class_sentinel",    '\0'}
  87. };
  88.  
  89. /*
  90.  *    DefScan () -- Scan symbol table to find macros, classes, mailers, 
  91.  *              and rulesets which have been referenced or declared, but
  92.  *              not defined.  A warning is printed for each such 
  93.  *              occurence.  This routine is usually called at the end
  94.  *              of a successful Ease translation.
  95.  *
  96.  */
  97. void
  98. DefScan ()
  99. {
  100.     register int stindex;        /* symbol table hash index   */
  101.     register struct he *hcsearch;    /* hash chain search pointer */
  102.  
  103.     for (stindex = 0; stindex < SST; stindex++) {
  104.         if ((hcsearch = SymTab[stindex]) != NULL)
  105.             while (hcsearch != NULL) {
  106.                 if ((ISMACRO(hcsearch->idtype) && 
  107.                      isupper(hcsearch->idval.idc)) &&
  108.                      !ISMACRO(hcsearch->idd))
  109.                     PrintWarning ("Macro not defined: %s\n", hcsearch->psb);
  110. #ifdef notdef
  111.                 if (ISCLASS(hcsearch->idtype) && !ISCLASS(hcsearch->idd))
  112. #else
  113.                 /* FLUKE jps 28-apr-86 */
  114.                 /* print warnings for UPPER CASE names only */
  115.                 if (ISCLASS(hcsearch->idtype) &&
  116.                     isupper(hcsearch->idval.idc) &&
  117.                     !ISCLASS(hcsearch->idd))
  118. #endif
  119.                     PrintWarning ("Class not defined: %s\n", hcsearch->psb);
  120.                 if (ISMAILER(hcsearch->idtype) && !ISMAILER(hcsearch->idd) && (strcmp(hcsearch->psb,"LOCAL")))
  121.                     PrintWarning ("Mailer not defined: %s\n", hcsearch->psb);
  122.                 if (ISRULESET(hcsearch->idtype) && !ISRULESET(hcsearch->idd))
  123.                     PrintWarning ("Ruleset not defined: %s\n", hcsearch->psb);
  124.                 hcsearch = hcsearch->phe;
  125.             }
  126.     }
  127. }
  128.                      
  129.  
  130. /*
  131.  *    InitSymbolTable () -- Invoked by main () to initialize the symbol table.
  132.  *
  133.  */
  134. void
  135. InitSymbolTable ()
  136. {
  137.     int i;
  138.  
  139.     for (i = 0; i < SST; i++)        /* initialize base array */
  140.         SymTab[i] = NULL;
  141. }
  142.  
  143.  
  144. /*
  145.  *    PreLoad () -- Invoked by main () to preload special macro names 
  146.  *              and mailer declarations.
  147.  *
  148.  */
  149. void
  150. PreLoad ()
  151. {
  152.     struct Defmac *macptr;
  153.     struct he     *symptr;
  154.  
  155.     /* preload special (lower-case) macros */
  156.     for (macptr = &MacDefs[0]; (*macptr).macrep != '\0'; macptr++) {
  157.         symptr = LookupSymbol ((*macptr).macname);
  158.         symptr->idtype |= ID_MACRO;
  159.         symptr->idval.idc = (*macptr).macrep;
  160.     }
  161.  
  162.     /* preload special (lower-case) classes */
  163.     for (macptr = &ClassDefs[0]; (*macptr).macrep != '\0'; macptr++) {
  164.         symptr = LookupSymbol ((*macptr).macname);
  165.         symptr->idtype |= ID_CLASS;
  166.         symptr->idval.idc = (*macptr).macrep;
  167.     }
  168.  
  169.     /* preload error mailer declaration */
  170.     symptr = LookupSymbol (ERRORMAILER);
  171.     symptr->idtype |= ID_MAILER;
  172.     symptr->idd |= ID_MAILER;
  173.  
  174.     /* preload ERROR mailer declaration */
  175.     symptr = LookupSymbol (ERRORMAILERUC);
  176.     symptr->idtype |= ID_MAILER;
  177.     symptr->idd |= ID_MAILER;
  178. }
  179.     
  180.  
  181. /*
  182.  *    LookupSymbol () -- Returns a pointer to the hash entry already 
  183.  *               existing, or newly created, which corresponds 
  184.  *               to string sb.
  185.  *
  186.  */
  187. struct he *
  188. LookupSymbol (sb)
  189. char sb[];            /* string buffer containing identifier */
  190. {
  191.     struct he *phe;        /* hash entry search pointer  */
  192.     int      hc;        /* hash code of sb identifier */
  193.     extern char *malloc ();
  194.  
  195.     phe = SymTab[hc = HashCode (sb)];
  196.     while (phe != NULL)            /* find hash entry for sb */
  197.         if (!strcmp (phe->psb, sb))
  198.             return (phe);
  199.         else
  200.             phe = phe->phe;
  201.     /* make new symbol table entry */
  202.     if ((phe = (struct he *) malloc (sizeof (struct he))) == NULL)
  203.         FatalError ("System out of space in LookupSymbol ()", (char *) NULL);
  204.     if ((phe->psb = (char *) malloc (strlen (sb) + 1)) == NULL)
  205.         FatalError ("System out of space in LookupSymbol ()", (char *) NULL);
  206.     strcpy (phe->psb, sb);
  207.     phe->idval.idc = '\0';
  208.     phe->idtype = ID_UNTYPED;
  209.     phe->idd = ID_UNTYPED;
  210.     phe->phe = SymTab[hc];
  211.     return (SymTab[hc] = phe);
  212. }
  213.  
  214.  
  215. /*
  216.  *    RemoveSymbol () -- Removes the symbol table entry phe from the 
  217.  *               symbol table.
  218.  *
  219.  */
  220. void
  221. RemoveSymbol (phe)
  222. struct he *phe;       /* pointer to hash entry to be removed from symbol table */
  223. {
  224.     int hc;               /* hash code of entry phe       */
  225.     struct he *sphe;    /* search pointer for entry phe */
  226.  
  227.     if (phe == NULL)
  228.         return;
  229.     else {            /* search and remove entry phe  */
  230.         sphe = SymTab[hc = HashCode (phe->psb)];
  231.         free (phe->psb);
  232.         if (sphe == phe)
  233.             SymTab[hc] = phe->phe;
  234.         else
  235.             while (sphe != NULL)
  236.                 if (sphe->phe == phe) {
  237.                     sphe->phe = phe->phe;
  238.                     return;
  239.                 } else
  240.                     sphe = sphe->phe;
  241.     }
  242. }
  243.  
  244.  
  245. /*
  246.  *    HashCode () -- Returns the hash code of the string in sb by adding 
  247.  *               the character values and applying mod by the hash 
  248.  *               table size.
  249.  *
  250.  */
  251. int
  252. HashCode (sb)
  253. char sb[];
  254. {
  255.     int ccSum = 0;            /* sum of char values in string sb */
  256.     int i;
  257.  
  258.     for (i = 0; sb[i]; i++)        /* add char codes for sb chars     */
  259.         ccSum += sb[i];
  260.     return (ccSum % SST);        /* return sum mod table size       */
  261. }
  262.